//
//  UIBarButonItem+Extensions.swift
//  MyWeiBo
//
//  Created by 俞存旭 on 16/9/27.
//  Copyright © 2016年 俞存旭. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
   
    // -parameter title: title
    // -parameter fontSize: fontSize,默认16号
    // -parameter target: target
    // -parameter action: action
    // -parameter isBack: 是否是返回按钮如果是加上箭头
    
    // -returns UIBarButtonItem
    //
    convenience init(title: String,fontSize: CGFloat = 16,target: AnyObject?,action: Selector,isBack: Bool = false) {
        
        
        let btn: UIButton = UIButton(type: .custom)
        btn.frame = CGRect(x: 0, y: 10, width: 60, height: 30)
        btn.setTitle(title, for: .normal)
        btn.titleLabel?.textAlignment = .center
        btn.titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        btn.setTitleColor(UIColor.orange , for: .highlighted)
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        
        if isBack {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named: imageName), for: .normal)
            btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
        }
        
        self.init(customView: btn)
        
       
    }
}

